package com.yssoft.service.special;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import javax.annotation.Resource;

import com.yssoft.entity.special.TsSuspensionResumptionEntity;
import com.yssoft.mapper.special.TsSuspensionResumptionMapper;
import com.yssoft.utils.UploadFile;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * 企业停复产Service接口
 * @author: ZhouZhou
 * @date 2025-07-26 18:05:10
 */
@Service
public class TsSuspensionResumptionService extends ServiceImpl<TsSuspensionResumptionMapper, TsSuspensionResumptionEntity> {

	@Resource
	private TsSuspensionResumptionMapper tsSuspensionResumptionMapper;

	/**
	 * mybaitis-plus 单表页面分页查询
     */
	/*public PageUtil findPage(Map<String, Object> params) {
		QueryWrapper<TsSuspensionResumptionEntity> queryWrapper = new QueryWrapper<TsSuspensionResumptionEntity>();
		String companyId = (String) params.get("companyId");
		String deleteFlag = (String) params.get("deleteFlag");
		String year = (String) params.get("year");
		String isHaltProduction = (String) params.get("isHaltProduction");
		String samplingInspection = (String) params.get("samplingInspection");
		String report = (String) params.get("report");
		String deleteTime = (String) params.get("deleteTime");
		String createId = (String) params.get("createId");
		String updateId = (String) params.get("updateId");
		String deleteId = (String) params.get("deleteId");
		Page<TsSuspensionResumptionEntity> page = tsSuspensionResumptionMapper.selectPage(new Query<TsSuspensionResumptionEntity>(params).getPage(), queryWrapper);
		return new PageUtil(page);
    }*/

	/**
	 * 自定义分页查询，含关联实体对像
	 */
	/*public PageUtil findPage(Map<String, Object> params,TsSuspensionResumptionEntity tsSuspensionResumptionEntity) {
		params.put("__limit", "10000");
		params.put("__page", "0");
		tsSuspensionResumptionEntity.setCompanyId(Long.parseLong(tsSuspensionResumptionEntity.getId()));

		Page<TsSuspensionResumptionEntity> page = tsSuspensionResumptionMapper.findPage(new Query<TsSuspensionResumptionEntity>(params).getPage(),
					tsSuspensionResumptionEntity,
				(String) params.get(Constant.SQL_FILTER));
		return new PageUtil(page);
	}*/

	/**
	* 查列表
	*/
	public List<TsSuspensionResumptionEntity> findList(TsSuspensionResumptionEntity tsSuspensionResumptionEntity){
		return tsSuspensionResumptionMapper.findList(tsSuspensionResumptionEntity);
	}

	/**
	 * 保存
	 */
	@Transactional(rollbackFor = Exception.class)
	public boolean addTsSuspensionResumption(TsSuspensionResumptionEntity entity, MultipartFile file){
		entity.setId(UUID.randomUUID().toString().replaceAll("-", ""));
		// 处理文件上传
		if (file != null && !file.isEmpty()) {
			String report = UploadFile.processUploadedFile(file);
			if (report != null) {
				entity.setReport(report);
			}
		}
		if(this.save(entity)){
			return true;
		}
		return false;
	}

	/**
	 * 修改根居ID
	 */
	@Transactional(rollbackFor = Exception.class)
	public boolean update(TsSuspensionResumptionEntity entity,MultipartFile file) {
		// 如果有新文件上传，处理文件上传
		if (file != null && !file.isEmpty()) {
			String report = UploadFile.processUploadedFile(file);
			if (report != null) {
				entity.setReport(report);
			}
		}
		// 注意：如果没有上传新文件，不设置 report 字段，让 updateById 保持原值
		if(this.updateById(entity)){
			return true;
		}
		return false;
	}

	/**
	 * 软删除
	 */
	@Transactional(rollbackFor = Exception.class)
	public boolean delete(TsSuspensionResumptionEntity entity) {
		entity.setDeleteFlag(1);
		return this.updateById(entity);
	}
}
